package com.zr.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.zr.dao.FuncDao;
import com.zr.model.LMfuncs;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 这是系统功能的dao层
 * @author Administrator
 *
 * @param <T>
 */
@Repository(value="funcdao")
public class FuncDaoImpl<T> extends BaseDaOImpl<T> implements FuncDao{

	@Override
	public JSONArray getFuncByParentIdAndFids(int parentid, String ids) {
		// TODO Auto-generated method stub
		String[] id = ids.split(",");
		JSONArray funcs = new JSONArray();
		String hql = "from LMfuncs f where f.fparentid=:parentid";
		Query query = this.getCurrentSession().createQuery(hql);
		query.setInteger("parentid", parentid);
		List<LMfuncs> f = query.list();
		for (LMfuncs func : f) {
			JSONObject jo = new JSONObject();
			boolean flag = false;
			for (int i = 0; i < id.length; i++) {
				if(func.getFid() == Integer.parseInt(id[i])){
					flag = true;
					break;
				}
			}
			if(flag){
				jo.put("id", func.getFid());
				jo.put("text", func.getFname());
				if(func.getFstate().equals("open")){
					jo.put("iconCls", "icon-filter");
				}else{
					jo.put("iconCls", "icon-sum");
				}
				jo.put("state", func.getFstate());
				JSONObject attr = new JSONObject();
				attr.put("fpath", func.getFpath());
				jo.put("attributes", attr);
				funcs.add(jo);
			}
		}
		return funcs;
	}
}
